using System;

namespace WiredBrain.Helpers
{
    public class OrderChecker //已注册为单例
    {
        private readonly Random random;
        private int index;

        private readonly string[] status =
            {"Grinding beans", "Steaming milk", "Taking a sip (quality control)", "On transit to counter", "Picked up"};

        public OrderChecker(Random random)
        {
            this.random = random;
        }
        public void Reset() {
            index = 0;
        }
        public CheckResult GetUpdate(int orderNo)
        {
            if (random.Next(1, 7) > 4) //1,2.3,4,5,6 随机 1/3概率
            {
                if (status.Length -1 > index)
                {
                    index++;
                    var result = new CheckResult
                    {
                        New = true,
                        Update = status[index],
                        Finished = status.Length - 1 == index
                    };
                    return result;
                }
            }

            return new CheckResult {New = false};
        }
    }

    public class CheckResult
    {
        public bool New { get; set; }
        public string Update { get; set; }
        public bool Finished { get; set; }
        public override ToString(){
            return $"new is {New},update is {Update},Finished is {Finished}";
        }
    }
}
